package leetcode;

import java.util.Arrays;

public class Test1608 {
    public int specialArray(int[] nums) {
        Arrays.sort(nums);
        //System.out.println(nums[0]);
        for(int i=1;i<=nums.length;i++){
            int index=nums.length-i;
            //System.out.println("index"+nums[index]+"i"+i);
            if(nums[index]>=i){
                if(index==0)
                    return i;
                else if(nums[index-1]<i)
                    return i;
            }
            else
                break;
        }

        return -1;
    }
}
